package com.kg.fiber.view;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JLabel;
import javax.swing.JPanel;

import com.ivan.toolkit.common.Inputs;
import com.ivan.toolkit.swing.ConfigDialog;
import com.ivan.toolkit.swing.PromptTextField;
import com.kg.fiber.FiberviewApplication;
import com.kg.fiber.service.NodeBoss;

public class AddNodeDialog extends ConfigDialog {


	/**
	 * 
	 */
	private static final long serialVersionUID = -3852165769391417626L;
	private PromptTextField promptTextFieldHost;
	private PromptTextField promptTextFieldMark;

	/**
	 * Create the dialog.
	 */
	public AddNodeDialog() {
		cancelButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		okButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		setTitle("添加监测点");
		setBounds(100, 100, 645, 211);
		
		JPanel panel = new JPanel();
		getContentPane().add(panel, BorderLayout.CENTER);
		GridBagLayout gbl_panel = new GridBagLayout();
		gbl_panel.columnWidths = new int[]{20, 0, 0, 20, 0};
		gbl_panel.rowHeights = new int[]{0, 0, 0, 0, 0};
		gbl_panel.columnWeights = new double[]{0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
		gbl_panel.rowWeights = new double[]{1.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
		panel.setLayout(gbl_panel);
		
		JLabel label = new JLabel("节点网络地址：");
		label.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		GridBagConstraints gbc_label = new GridBagConstraints();
		gbc_label.anchor = GridBagConstraints.EAST;
		gbc_label.insets = new Insets(0, 0, 5, 5);
		gbc_label.gridx = 1;
		gbc_label.gridy = 1;
		panel.add(label, gbc_label);
		
		promptTextFieldHost = new PromptTextField();
		promptTextFieldHost.setFont(new Font("宋体", Font.PLAIN, 24));
		promptTextFieldHost.getNullLabel().setText("输入节点IP地址，如：127.0.0.1");
		GridBagConstraints gbc_promptTextFieldHost = new GridBagConstraints();
		gbc_promptTextFieldHost.insets = new Insets(0, 0, 5, 5);
		gbc_promptTextFieldHost.fill = GridBagConstraints.HORIZONTAL;
		gbc_promptTextFieldHost.gridx = 2;
		gbc_promptTextFieldHost.gridy = 1;
		panel.add(promptTextFieldHost, gbc_promptTextFieldHost);
		
		JLabel label_1 = new JLabel("节点告警信息：");
		label_1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		GridBagConstraints gbc_label_1 = new GridBagConstraints();
		gbc_label_1.anchor = GridBagConstraints.EAST;
		gbc_label_1.insets = new Insets(0, 0, 5, 5);
		gbc_label_1.gridx = 1;
		gbc_label_1.gridy = 2;
		panel.add(label_1, gbc_label_1);
		
		promptTextFieldMark = new PromptTextField();
		promptTextFieldMark.setFont(new Font("宋体", Font.PLAIN, 24));
		promptTextFieldMark.getNullLabel().setText("输入节点告警信息");
		GridBagConstraints gbc_promptTextFieldMark = new GridBagConstraints();
		gbc_promptTextFieldMark.insets = new Insets(0, 0, 5, 5);
		gbc_promptTextFieldMark.fill = GridBagConstraints.HORIZONTAL;
		gbc_promptTextFieldMark.gridx = 2;
		gbc_promptTextFieldMark.gridy = 2;
		panel.add(promptTextFieldMark, gbc_promptTextFieldMark);
		
	}

	@Override
	protected void doCommit() throws Exception {

		Inputs.at(promptTextFieldHost.getText(), "节点网络地址")._ip();
		
		Inputs.at(promptTextFieldMark.getText(), "节点告警信息")._notEmpty();
		
		NodeBoss boss = FiberviewApplication.getSpring().getBean(NodeBoss.class);
		boss.createNode(promptTextFieldHost.getText(), promptTextFieldMark.getText());
		
	}
	
	
	

}
